package org.fruitrecognitionbasedonai.fruitrecognitionbasedonai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import org.fruitrecognitionbasedonai.fruitrecognitionbasedonai.entity.User;
import org.fruitrecognitionbasedonai.fruitrecognitionbasedonai.entity.UserRecord;
import org.fruitrecognitionbasedonai.fruitrecognitionbasedonai.mapper.UserRecordMapper;
import org.fruitrecognitionbasedonai.fruitrecognitionbasedonai.service.IUserRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: Re
 * @Date: 2021/6/19 23:17
 */
@Service
public class UserRecordServiceImpl implements IUserRecordService {
    @Autowired
    protected UserRecordMapper userRecordMapper;
    @Override
    public boolean insert(UserRecord userRecord) {
        return userRecordMapper.insert(userRecord) == 1;
    }

    @Override
    public boolean deleteById(Integer id) {
        return userRecordMapper.deleteById(id) == 1;
    }

    @Override
    public boolean deleteByUserId(Integer userId) {
        LambdaQueryWrapper<UserRecord> queryWrapper = new LambdaQueryWrapper<UserRecord>()
                .eq(UserRecord::getUserId,userId);
        return userRecordMapper.delete(queryWrapper) >= 0;
    }

    @Override
    public boolean deleteByRecordId(Integer recordId) {
        LambdaQueryWrapper<UserRecord> queryWrapper = new LambdaQueryWrapper<UserRecord>()
                .eq(UserRecord::getRecordId,recordId);
        return userRecordMapper.delete(queryWrapper) == 1;
    }

    @Override
    public UserRecord selectById(Integer userRecordId) {
        return userRecordMapper.selectById(userRecordId);
    }

    @Override
    public List<UserRecord> selectByUserId(Integer userId) {
        return new LambdaQueryChainWrapper<UserRecord>(userRecordMapper)
                .eq(UserRecord::getUserId,userId).list();

    }
}
